<?php

	/**
	 * to_attr_str
	 *
	 * @param array $arr
	 * @return string
	 * 
	 * @example 
	 * echo to_attr_str(array("name"=>"image","type"=>"text")) //out name="image" type="text"
	 */
	function to_attr_str($arr){
		$attrs = array();
		foreach($arr as $k=>$v){
			$attrs[] = "{$k}=\"".htmlspecialchars($v)."\"";
		}
		return implode(" ",$attrs);
	}
	
	
	$__tagindex=0;
	function tagid(){
		global $__tagindex;
		return "tag_".(++$__tagindex);
	}


	function tag_input($type,$params){
		global $__view;
		
		$attrs = $params;
		
		//get record
		if(ereg("^([0-9a-zA-Z_]*).*",$params["name"],$regs) && empty($params["value"])){ //record
			$recordname = $regs[1];
			$arraypath = substr($params["name"],strlen($recordname));
			$attrs["value"]=array_readone($__view->$recordname,$arraypath);
		}
		
		unset($attrs["type"]);
		
		return sprintf("<input type=\"{$type}\" %s />",to_attr_str($attrs));
	}
	
	function tag_input_text($params){
		return tag_input("text",$params);
	}
	function tag_input_hidden($params){
		return tag_input("hidden",$params);
	}
	
	function tag_input_submit(){
		
	}
	
	function tag_input_select($params){
		
	}
	
	
	
?>